package com.qihoo.mm.camera.collage.template.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

import seekting.demo2017.AppEnv;

/**
 * Created by seekting on 17-5-16.
 */

public class TemplateWorkSpace extends FrameLayout {
    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = "TemplateWorkSpace";

    public TemplateWorkSpace(Context context) {
        super(context);
    }

    public TemplateWorkSpace(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
        int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
        if (maxWidth == 0 || maxHeight == 0) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }
        int width = 0;
        int height = 0;
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            child.measure(widthMeasureSpec, heightMeasureSpec);
            width = Math.max(child.getMeasuredWidth(), width);
            height = Math.max(child.getMeasuredHeight(), height);
        }
        setMeasuredDimension(width, height);
        if (DEBUG) {
            Log.d(TAG, "onMeasure.width=" + width + ",height=" + height);
        }
    }
}
